from typing import *
from leetcode.editor.common.node import *


# leetcode submit region begin(Prohibit modification and deletion)
class Solution(object):
    def corpFlightBookings(self, bookings, n):
        arr = [0]*n
        df = self.Defferent(arr)
        for boolk in bookings:
            left, right, inc = boolk[0], boolk[1], boolk[2]
            df.increment(left-1, right-1, inc)
        return df.result()

    class Defferent():
        def __init__(self,arr):
            self.per_nums = [arr[0]]+[arr[i]-arr[i-1]  for i in range(1, len(arr))]

        def increment(self,left,right,inc):
            self.per_nums[left] += inc
            if right+1 < len(self.per_nums):
                self.per_nums[right+1] -= inc
        def result(self):
            res = [0] * len(self.per_nums)
            # 根据差分数组构造结果数组
            res[0] = self.per_nums[0]
            for i in range(1, len(self.per_nums)):
                res[i] = res[i - 1] + self.per_nums[i]
            return res

# leetcode submit region end(Prohibit modification and deletion)


if __name__ == '__main__':
    solution = Solution()
    print(solution.corpFlightBookings([[1,2,10],[2,3,20],[2,5,25]],5))
    # your test code here